'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    // 添加用户个人资料相关字段
    await queryInterface.addColumn('users', 'avatar_url', {
      type: Sequelize.STRING(500),
      allowNull: true,
      comment: '用户头像URL',
      after: 'password_hash',
    });

    await queryInterface.addColumn('users', 'nickname', {
      type: Sequelize.STRING(50),
      allowNull: true,
      comment: '用户昵称',
      after: 'avatar_url',
    });

    await queryInterface.addColumn('users', 'gender', {
      type: Sequelize.ENUM('male', 'female', 'other'),
      allowNull: true,
      comment: '性别：male-男，female-女，other-其他',
      after: 'nickname',
    });

    await queryInterface.addColumn('users', 'phone', {
      type: Sequelize.STRING(20),
      allowNull: true,
      unique: true,
      comment: '手机号',
      after: 'gender',
    });

    await queryInterface.addColumn('users', 'email', {
      type: Sequelize.STRING(100),
      allowNull: true,
      unique: true,
      comment: '邮箱地址',
      after: 'phone',
    });

    await queryInterface.addColumn('users', 'bio', {
      type: Sequelize.STRING(500),
      allowNull: true,
      comment: '个人简介',
      after: 'email',
    });

    // 添加索引
    await queryInterface.addIndex('users', ['phone'], {
      name: 'idx_phone',
      unique: true,
    });

    await queryInterface.addIndex('users', ['email'], {
      name: 'idx_email',
      unique: true,
    });

    console.log('✅ User profile fields added successfully');
  },

  async down(queryInterface, Sequelize) {
    // 删除索引
    await queryInterface.removeIndex('users', 'idx_phone');
    await queryInterface.removeIndex('users', 'idx_email');

    // 删除列
    await queryInterface.removeColumn('users', 'bio');
    await queryInterface.removeColumn('users', 'email');
    await queryInterface.removeColumn('users', 'phone');
    await queryInterface.removeColumn('users', 'gender');
    await queryInterface.removeColumn('users', 'nickname');
    await queryInterface.removeColumn('users', 'avatar_url');

    console.log('✅ User profile fields removed successfully');
  },
};


